package com.bupt.controller;

import com.bupt.bean.ChannelSection;
import com.bupt.bean.Device;
import com.bupt.bean.DeviceType;
import com.bupt.config.DeviceResult;
import com.bupt.config.Result;
import com.bupt.config.SectionResult;
import com.bupt.dao.SectionRepository;
import com.bupt.service.SectionService;
import com.bupt.vo.ChannelSectionVo;
import com.bupt.vo.SysConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(value="通道区域接口",description="通道下区域的增删改查、报警端点")
@RestController
public class SectionController {

    @Autowired
    private SectionRepository sectionRepository;

    @Autowired
    private SectionService sectionService;



    @ApiOperation("通过设备通道ID查询通道的区域信息")
    @GetMapping("/section/channelSectionById/{deviceChannelId}")
    public List<ChannelSectionVo> channelSectionById(@PathVariable("deviceChannelId") Integer deviceChannelId) {
        return sectionService.channelSectionById(deviceChannelId);

    }

    @ApiImplicitParams({@ApiImplicitParam(name="endpointSwitch",value="是否开启端点报警(接口和/deviceTypeAttribute/enableDevice是同一个接口)",required=true,paramType="query",dataType="int"),@ApiImplicitParam(name="endpoint",value="报警端点(endpoint直接传const_desc的值)",required=true,paramType="query",dataType="string")})
    @ApiOperation("通道区域信息添加页面")
    @PostMapping("/section/add")
    public SectionResult add(@RequestParam("deviceChannelId") Integer deviceChannelId, @RequestParam("sectionName") String sectionName, @RequestParam("startPosition") Float startPosition, @RequestParam("endPosition") Float endPosition,@RequestParam("endpointSwitch") Integer endpointSwitch,@RequestParam("endpoint") String endpoint) {
        return sectionService.add(deviceChannelId, sectionName, startPosition, endPosition,endpointSwitch,endpoint);
    }


    @ApiOperation("删除通道下的某个区域信息")
    @DeleteMapping("/section/deleteById/{channelSectionId}")
    public Result deleteById(@PathVariable("channelSectionId") Integer channelSectionId) {
        return sectionService.deleteById(channelSectionId);
    }

    @ApiOperation("通过IP修改单个区域信息")
    @PutMapping("/section/edit/{deviceChannelId}/{channelSectionId}")
    public SectionResult editSectionById(@PathVariable("deviceChannelId") Integer deviceChannelId,@PathVariable("channelSectionId") Integer channelSectionId, @RequestParam("sectionName") String sectionName, @RequestParam("startPosition") Float startPosition, @RequestParam("endPosition") Float endPosition,@RequestParam("endpointSwitch") Integer endpointSwitch,@RequestParam("endpoint") String endpoint) {
        return sectionService.editSectionById(deviceChannelId,channelSectionId, sectionName, startPosition, endPosition,endpointSwitch,endpoint);
    }


    @ApiOperation("报警端点")
    @GetMapping("/endpoint")
    public List<SysConst> endpoint() {
        return sectionService.endpoint();
    }
}
